<template>
	<view class="container">
		<view class="subsite-banner">
			<image src="https://www.fzftjc.com/static/rs/itorder/applet/breadcrumb-bg.jpg" mode="widthFix">
				<view class="subsite-caption">
					<view class="fz18">产业报国 服务利民</view>
				</view>
		</view>
		<!-- News -->
		<view class="subsite subsite-with-banner">
			<view class="subsite-heading">
				<view class="section-main-title fz18"><text>//</text>产品中心<text>//</text></view>
				<view class="subsite-tabs">
					<uni-segmented-control :current="current" :values="items" :style-type="styleType" @clickItem="onClickItem" />
				</view>
			</view>
			<view class="subsite-row">
				<view v-if="current === k" v-for="(v , k) in items">
					<view class="flex-wrap">
						<navigator :url="'product-show?product_id='+value.id" hover-class="none" v-for="(value,index) in product" class="pro-card">
							<view class="pro-card-img">
								<image :src="value.thumb" mode="aspectFill"></image>
							</view>
							<view class="uni-flex-item pro-card-desc">
								<view class="fz16 line">{{value.name}}</view>
								<view class="c-gray fz12">{{value.sub_name}}</view>
								<view class="fz12 c-gray9 ellipsis-l3">适用范围：<text class="">{{value.scope}}</text></view>
							</view>
						</navigator>
					</view>
				</view>
			</view>
			<view class="flex-center">
				<uni-pagination :total="total" @change="next" :current="page" :pageSize="4" title="标题文字" />
			</view>
		</view>
		<!-- News end-->
		<!-- Footer -->
		<relation></relation>
	</view>
</template>

<script>
	import relation from'../public/relation.vue';
	import base from '../../js/base.js';
	import app from '../../js/app.js';
	export default {
		components:{
			relation
		},
		data() {
			return {
				items: ['防水浆料', '防水涂料', '瓷砖胶/背胶','加固剂' ],
				current: 0,
				styleType: 'button',
				data:[],
				page:1,
				product:{},
				total:0
			}
		},
		mounted() {
			this.category();
		},
		methods: {
			next(e){
				var This = this;
				base.request({
					url:base.urltext('/itorder/home_port/product_list'),
					header:{ 'content-type': 'application/x-www-form-urlencoded' },
					data:{ page:e.current,cate_id:This.data[this.current].id},
					success:function(res){
						if(res.data.success>0)
						{
							This.product = res.data.list;
							This.total = res.data.total;							
						}
					}
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为：' + e.detail.value)
				this.index = e.detail.value
			},
			onClickItem(e) {
				let This=this;
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
				base.request({
					url:base.urltext('/itorder/home_port/product_list'),
					header:{ 'content-type': 'application/x-www-form-urlencoded' },
					data:{ page:1,cate_id:This.data[e.currentIndex].id},
					success:function(res){
						if(res.data.success>0)
						{
							This.product = res.data.list;
							This.total = res.data.total;
							//This.page =1;
							//This.total = 0;
							
						}
					}
				})
			},
			category(){
				//产品分类列表
				let This = this;
				base.request({
					url:base.urltext('/itorder/home_port/category_list'),
					success:function(res){
						var data = res.data.list;
						var arr = [];
						if(res.data.success>0)
						{
							for(var i in data)
							{
								arr.push(data[i].name);
							}
							if(arr)
							{
								This.items=arr;
								This.data = data;
								This.onClickItem({currentIndex:0});
							}else{
								uni.showToast({
								    title: '无分类列表数据', mask: true, duration: 2500, icon: 'none'
								});
							}
						}
					}
				});
			}
		}
	}
</script>

<style>
	
</style>
